/*=============================================================================
#    The element-comm is a tentative program used to test our ideas.           
#                       Copyright (C)  bgao                                    
#
#     This program is free software; you can redistribute it and/or            
#      modify it under the terms of the GNU General Public License             
#     as published by the Free Software Foundation; either version 2           
#         of the License, or (at your option) any later version.               
#
#     This program is distributed in the hope that it will be useful,          
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            
#             GNU General Public License for more details.                    
#
#    You should have received a copy of the GNU General Public License        
#     along with this program; if not, write to the Free Software             
#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,             
#                       MA  02110-1301, USA.                                  
#==============================================================================
# $Id: mac_queue.c 348 2010-11-29 09:01:16Z bgao $ 
#
# $Author: bgao $ 
#
# $Revision: 348 $ 
#
# $Date: 2010-11-29 17:01:16 +0800 (星期一, 29 十一月 2010) $ 
#
# Description: 
#
=============================================================================*/
/*! @file mac_queue.c
 *  @brief This file implements the queue module used by the MAC to
 *         buffer received frames.
 */
#include <string.h>
#include <stdlib.h>
#include "mac_queue.h"

#define MAC_QUEUE_BUF_COUNT 10

/* define an instance of list to represent mac_queue */
LIST(mac_queue);

/*! initialize the mac queue.
 *  @return MAC_ERR(-1) if the list or the mem sub module malfunction
 *          else return MAC_OK(1).
 */
int8 mac_queue_init(void)
{
    return list_init(mac_queue);
}

/*! allocate a entry from the mac queue.
 *  @return if the buf is pushed to queue successfully.
 */
int8 mac_queue_push(buf_t *buf)
{
    return list_add_tail(mac_queue, buf);
}

/*! free the allocated entry from mac queue.
 *  @return return MAC_ERR(-1) if no such entry exists else return MAC_OK(0).
 */
buf_t *mac_queue_pop(void)
{
    return list_del_head(mac_queue);
}

/*! check if the queue is emtpy
 *  @return returns true if the queue is empty, else returns false
 */
bool mac_queue_is_empty(void)
{
    return list_is_empty(mac_queue);
}
